<%-- 
    Document   : check.jsp
    Created on : 2014/2/26, 下午 01:08:41
    Author     : Gjun
--%>
<%@page import="java.util.HashMap"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
        ArrayList<comm.comm> rsList=(ArrayList)session.getAttribute("rsList");  
        String address=request.getParameter("address");
        
    %>
<!DOCTYPE html>
<html> 
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>結帳頁面</title>
    </head>
    <body>
        <h1>結帳頁面</h1>
        <%
               String nocomm="";
               db.DAO dao=new db.DAO();
                for(comm.comm c:rsList)
                        {
                                int dd= dao.checkcomm(c); 
                                if(dd!=-1)
                                    nocomm+=c.getName()+":剩餘:"+dd+"個， ";                           
                         }                
                    if(nocomm==""){
                if(rsList!=null){    
                     dao.updatecomm(rsList);
                    int inserts=dao.insert(session.getAttribute("user")+"",address,rsList);
                                        
                         if(inserts!=0){
        %>
                    
                    收件人:&nbsp;&nbsp;&nbsp;<%=session.getAttribute("user")%><br>
                    地址:&nbsp;&nbsp;&nbsp;  <%=address%><br>                      
                    <table border="2">
                <tr><td>商品名稱</td><td>單價</td><td>數量</td><td>價錢</td></tr>
             <%                
                int allprice=0;
                for(comm.comm c:rsList)
                {                    
                    out.print("<tr><td>");
                    out.print(c.getName()+"</td><td>");
                    out.print(c.getPrice()+"</td><td>");
                    out.print(c.getAddnum()+"</td><td>");                    
                    out.print( Integer.parseInt(c.getPrice())*c.getAddnum()+"</td></tr>"); 
                    allprice+=(Integer.parseInt(c.getPrice())*c.getAddnum());
                } 
                
                    session.removeAttribute("rsList");
            %>

            <tr><td><font size="5">合計:&nbsp&nbsp<%=allprice%></font></td></tr>
            
            </table>            
           
           
            <form action="<%= response.encodeRedirectURL("del.jsp")%>" id="OK" method="post">
                    <input type="hidden" id="count" name="count">
            </form>
                    
                  <% 
                     }else{
                                out.print("訂購失敗");
                    }                   
                     }else{
                    %>
                    
                    <font size="5" color="red">訂購失敗</font>
                    <font size="5" color="red">購物車無商品，或商品已結帳</font>              
                    <%
                }
                    }else{
                        out.print(nocomm+"請重新選擇");%>
                        <form action="add.jsp"   method="post">
                                    <input type="submit" value="回購物車">
                        </form>
                        <%  }
                %>
                <form action="daocy.jsp">
                    <input type="submit" value="回商品目錄">
                </form>
                  
    </body>
</html>

